﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace TB_WS.Class
{
    public class Seller_User
    {
        public static int Get_User_Count(string User_Name,int Seller_ID)
        {
            string sql = "select count(*) from Seller_User where User_Name='"+
                User_Name + "' and Seller_ID=" + Seller_ID;
            return Convert.ToInt32(Class.Unit.db_Conn.scalar(sql));
        }

        public static int Conform_Login(int Seller_ID,string User_Name,string User_PWD)
        {
            string sql = "select count(*) from Seller_User where User_Name='" +
                User_Name + "' and Password='" + User_PWD + "' and Type='available' and Seller_ID="+Seller_ID;
            return Convert.ToInt32(Class.Unit.db_Conn.scalar(sql));
        }

        public static int insert_Seller_User(int Seller_ID,
            string User_Name,string User_PWD)
        {
            string sql = "insert into Seller_User values(" + Seller_ID
                + ",'" + User_Name + "','" + User_PWD + "','','available')";
            return Class.Unit.db_Conn.Nonquery(sql);
        }

        public static int update_user_pwd(int Seller_ID,
            string User_Name, string User_PWD)
        {
            string sql = "update Seller_User set Password='"+
                User_PWD+"' where User_Name='"+
                User_Name+"' and Seller_ID=" + Seller_ID;
            return Class.Unit.db_Conn.Nonquery(sql);
        }

        public static int update_user_type(int Seller_ID, string User_Name, string Type)
        {
            string sql = "update Seller_User set Type='" + Type + "' where User_Name='" + User_Name + "' and Seller_ID=" + Seller_ID;
            return Class.Unit.db_Conn.Nonquery(sql);
        }

        public static void update_last_login_time(int seller_ID,string User_Name)
        {
            string sql = "update Seller_User set Last_Login='"+
                LeShiTao_Library.Tools.Data_Handle.GET_UNIX_TIMESTAMP().ToString()+"' where User_Name='" + User_Name + "' and Seller_ID=" + seller_ID;
            Class.Unit.db_Conn.Nonquery(sql);
        }
        
        public static DataSet get_User_List(int seller_ID,string Type)
        {
            string sql = "select id,Seller_ID,User_Name,Password,dbo.from_unixtime(Last_Login)[Last_Login],Type from Seller_User where Seller_ID=" + seller_ID +" and Type like '%"+Type+"%'";
            return Class.Unit.db_Conn.select(sql);
        }
    }
}
